#!/usr/bin/python
# -*- coding: utf-8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

#Pytigon - wxpython and django application framework

#author: "Sławomir Chołaj (slawomir.cholaj@gmail.com)"
#copyright: "Copyright (C) ????/2012 Sławomir Chołaj"
#license: "LGPL 3.0"
#version: "0.1a"

import wx
import sys

from schcli.guilib.htmltools import HtmlErrorDialog

def http_error(parent, contents):
    lock = wx.GetApp().lock
    if not lock:
        wx.GetApp().lock = True

        if parent and hasattr(parent,'Invalidate'):
            parent.Invalidate()

        dlg = HtmlErrorDialog(wx.GetApp().GetTopWindow(), -1, "Error message", contents.decode('utf-8'), size=(800,600),
                              style=wx.DEFAULT_DIALOG_STYLE)
        dlg.CenterOnScreen()
        try:
            val = dlg.ShowModal()
        except:
            print("ERROR")
        wx.GetApp().lock = False

        if val == wx.ID_CANCEL:
            sys.exit()
